package com.patterns.proxy.commonDynamicProxy;

import com.patterns.proxy.commonDynamicProxy.proxy.DynamicProxy;
import com.patterns.proxy.commonDynamicProxy.proxy.MyInvocationHandler;
import com.patterns.proxy.commonDynamicProxy.subject.RealSubject;
import com.patterns.proxy.commonDynamicProxy.subject.Subject;

import java.lang.reflect.InvocationHandler;

/**
 * Created by Xiao Yiyun on 2017/4/24.
 */
public class Client {
    public static void main(String[] args) {
        //定义一个主题
        Subject subject = new RealSubject();
        //定义一个Handler
        InvocationHandler handler = new MyInvocationHandler(subject);
        //定义一个主题的代理
        Subject proxy =
                DynamicProxy.newProxyInstance(subject.getClass().getClassLoader(),
                        subject.getClass().getInterfaces(), handler);
        //代理的行为
        proxy.someMethods("Finish");
    }
}
